// pages/login/login.js

const appid = 'wxfa95692c8ac5f298';
const secret = 'e0abdf90b49491cb2732d9eb390de9db';
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  login(js_code){
      wx.showLoading({
        title: '登录中',
      })
      wx.request({
        url: 'http://192.168.70.101:9898/api/v1/user/login',
        data:{
          js_code:js_code,
          appid:appid,
          secret:secret,
        },
        success:(res)=>{
          wx.hideLoading()
          const token = res.data;
          wx.setStorageSync("token", token);
          

          //退回到上一个也
          wx.navigateBack({
            delta: 1
          })
        }
      })

  },

  toLogin(e){
      wx.login({
        success: (res) => {
            const {code}  = res;
            console.log("code: "+code);
            this.login(code)
        },
      })
  }
})